//
//  DemoArrayLoop.swift
//  swiftDemo
//
//  Created by JIENING ZHANG on 2020/1/7.
//  Copyright © 2020 lovivid. All rights reserved.
//

import UIKit

class DemoArrayLoop: NSObject {
    class func demoLogic() {
        let month = [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December",
        ];
        
        //var monthHasSubER = [String]() // 不推荐
        var monthHasSubER:[String] = []
        
        print("DemoArrayLoop, month.count=\(month.count)")
        print("DemoArrayLoop, monthHasSubER.count=\(monthHasSubER.count)")
        
        for mName in month {
            print("month for loop, mName=\(mName)");
            if mName.hasSuffix("er") {
                monthHasSubER.append(mName);
            }
        }
        
        for (index, mName) in monthHasSubER.enumerated() {
            print("monthHasSubER, index:\(index) mName=\(mName)");
        }
        
        month.forEach { (mName) in
            print("month forEach, mName=\(mName)")
        }
/*
输出:
     
DemoArrayLoop, month.count=12
DemoArrayLoop, monthHasSubER.count=0
month for loop, mName=January
month for loop, mName=February
month for loop, mName=March
month for loop, mName=April
month for loop, mName=May
month for loop, mName=June
month for loop, mName=July
month for loop, mName=August
month for loop, mName=September
month for loop, mName=October
month for loop, mName=November
month for loop, mName=December
monthHasSubER, index:0 mName=September
monthHasSubER, index:1 mName=October
monthHasSubER, index:2 mName=November
monthHasSubER, index:3 mName=December
month forEach, mName=January
month forEach, mName=February
month forEach, mName=March
month forEach, mName=April
month forEach, mName=May
month forEach, mName=June
month forEach, mName=July
month forEach, mName=August
month forEach, mName=September
month forEach, mName=October
month forEach, mName=November
month forEach, mName=December
*/
    }
}
